cmake_minimum_required(VERSION 3.15)
project(lidar_processing_cpp)

# 关键修复：在任何find_package之前设置这些变量和策略
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/usr/share/cmake-3.16/Modules/")
set(PythonInterp_FOUND TRUE)
set(PYTHON_EXECUTABLE /usr/bin/python3)
set(PYTHON_VERSION_STRING "3.8.10")  # 根据你的Python版本修改

# 处理所有相关的CMake策略
cmake_policy(SET CMP0148 NEW)
cmake_policy(SET CMP0144 NEW)
cmake_policy(SET CMP0167 NEW)
cmake_policy(SET CMP0072 NEW)
# 抑制CMP0144警告
# 处理Open3D的CMP0072警告



# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置Open3D的路径
set(Open3D_DIR $ENV{HOME}/open3d_install/lib/cmake/Open3D)

# 查找Python3（现代方式）
find_package(Python3 COMPONENTS Interpreter REQUIRED)

# 手动创建FindPythonInterp.cmake的替代逻辑
if(NOT PythonInterp_FOUND)
  set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
  set(PYTHON_VERSION_STRING ${Python3_VERSION_STRING})
  set(PythonInterp_FOUND TRUE)
endif()

# 查找ROS依赖
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(livox_interfaces REQUIRED)
find_package(pcl_conversions REQUIRED)
find_package(pcl_ros REQUIRED)
find_package(PCL REQUIRED COMPONENTS filters segmentation)

# 查找Open3D
find_package(Open3D REQUIRED)

# 添加可执行文件
add_executable(lidar_processor_cpp src/lidar_processor.cpp)

# 链接依赖库
ament_target_dependencies(lidar_processor_cpp
  rclcpp
  sensor_msgs
  livox_interfaces
  pcl_conversions
  pcl_ros
)

# 链接PCL和Open3D库
target_link_libraries(lidar_processor_cpp
  ${PCL_LIBRARIES}
  Open3D::Open3D
)

# 安装可执行文件
install(TARGETS
  lidar_processor_cpp
  DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY
  launch
  DESTINATION share/${PROJECT_NAME}
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  set(ament_cmake_copyright_FOUND TRUE)
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
    